package org.hpm.common.api.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;

/**
 * Hpm自定义响应数据结构，仅是对门户接口使用
 *
 * @author: jacklin
 * @date: 2022/8/31 0:13
 */
public class HpmResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    // 定义jackson对象
    private static final ObjectMapper MAPPER = new ObjectMapper();

    // 响应业务状态
    private Integer status;

    // 响应消息
    private String msg;

    // 响应中的数据
    private Object data;

    @JsonIgnore
    private String ok;    // 不使用

    public static HpmResult build(Integer status, String msg, Object data) {
        return new HpmResult(status, msg, data);
    }

    public static HpmResult build(Integer status, String msg, Object data, String ok) {
        return new HpmResult(status, msg, data, ok);
    }

    public static HpmResult ok(Object data) {
        return new HpmResult(data);
    }

    public static HpmResult ok(String msg, Object data) {
        return new HpmResult(200, msg, data);
    }

    public static HpmResult ok() {
        return new HpmResult(null);
    }

    public static HpmResult errorMsg(String msg) {
        return new HpmResult(500, msg, null);
    }

    public static HpmResult errorMap(Object data) {
        return new HpmResult(501, "error", data);
    }

    public static HpmResult errorTokenMsg(String msg) {
        return new HpmResult(502, msg, null);
    }

    public static HpmResult errorException(String msg) {
        return new HpmResult(555, msg, null);
    }

    public static HpmResult errorUserQQ(String msg) {
        return new HpmResult(556, msg, null);
    }

    public HpmResult() {

    }

    public HpmResult(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public HpmResult(Integer status, String msg, Object data, String ok) {
        this.status = status;
        this.msg = msg;
        this.data = data;
        this.ok = ok;
    }

    public HpmResult(Object data) {
        this.status = 200;
        this.msg = "OK";
        this.data = data;
    }

    public Boolean isOK() {
        return this.status == 200;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }

}
